package lru.review5_21;

import java.util.LinkedHashMap;
import java.util.Map;
//  CKG TODO 2023/5/21:  范型　没写　前后都没写
public class LRUCacheDemo1<K,V>   extends LinkedHashMap<K,V> {

    private int capacity;

    public LRUCacheDemo1(int initialCapacity) {
        super(initialCapacity, 0.75f, true);
        this.capacity=initialCapacity;
    }

    // 用于判断是否需要删除最近最久未使用的节点
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return super.size() > capacity;
    }

    public static void main(String[] args) {
        LRUCacheDemo1<Integer, Integer> demo = new LRUCacheDemo1<Integer, Integer>(3);
        demo.put(1,1);
        demo.put(2,2);
        demo.put(3,3);
        System.out.println(demo.keySet());
        demo.put(4,4);
        System.out.println(demo.keySet());
//        demo.put(3,3);
//        System.out.println(demo.keySet());
//        demo.put(3,3);
//        System.out.println(demo.keySet());
//        demo.put(3,3);
//        System.out.println(demo.keySet());



    }



}
